package cn.like.util;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.captcha.generator.RandomGenerator;


/**
 * Description: 验证码的创造者 <br>
 *
 * @author like 980650920@qq.com
 * @date 2021-07-13 16:03:48
 * @see cn.like.factory.CaptchaFactory 验证码创建工厂
 */
public abstract class CaptchaCreator {

    private static LineCaptcha lineCaptcha;
    private static CircleCaptcha circleCaptcha;

    /**
     * desc: 随机字符验证码生成器 可以通过传入的基础集合和长度随机生成验证码字符 <br>
     *
     * @return: {@link RandomGenerator }
     * @author: like 980650920@qq.com
     * @date 2021-07-08 13:16:30
     */
    public static RandomGenerator randomGenerator() {
        return new RandomGenerator("0123456789qwelkjzxcvbnm", 4);
    }

    public static LineCaptcha getLineCaptcha() {
        lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100);
        lineCaptcha.setGenerator(randomGenerator());
        lineCaptcha.createCode();
        return lineCaptcha;
    }

    public static CircleCaptcha getCircleCaptcha() {
        circleCaptcha = CaptchaUtil.createCircleCaptcha(200, 100);
        circleCaptcha.setGenerator(randomGenerator());
        circleCaptcha.createCode();

        return circleCaptcha;
    }
}
